package org.example.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Slf4j
//@Component
public class AspectDemo {
    @Pointcut("execution(* org.example.demo.controller.*.*(..))")
    public void pt() {

    }
    @Before("pt()")
    public void doBefore() {
        log.info("执行AspectDemo doBefore");
    }
    @After("pt()")
    public void doAfter() {
        log.info("执行AspectDemo doAfter");
    }
    @AfterReturning("execution(* org.example.demo.controller.*.*(..))")
    public void doAfterReturning() {
        log.info("执行AspectDemo doAfterReturning");
    }
    @AfterThrowing("execution(* org.example.demo.controller.*.*(..))")
    public void doAfterThrowing() {
        log.info("执行AspectDemo doAfterThrowing");
    }
    @Around("execution(* org.example.demo.controller.*.*(..))")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("执行AspectDemo doAround 前");
        Object result = joinPoint.proceed();
        log.info("执行AspectDemo doAround 后");
        return result;
    }
}
